package net.wanho.controller;


import net.wanho.po.Category;
import net.wanho.service.CategoryService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import lombok.RequiredArgsConstructor;



import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 分类表 前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2025-09-25
 */
@Api(tags = "07.分类表接口")
@RestController
@RequestMapping("/categories")
@RequiredArgsConstructor
public class CategoryController {

    private final CategoryService categoryService;

    @ApiOperation("商品分类列表")
    @GetMapping
    public AjaxResult findPage(@ApiParam("分类层级") @RequestParam(required = false, defaultValue = "3") Integer type,
                              @ApiParam("页码") @RequestParam(required = false) Integer pageNum,
                              @ApiParam("页大小") @RequestParam(required = false) Integer pageSize){
        Object obj = categoryService.find(type, pageNum,pageSize);
        return AjaxResult.success(obj);
    }

    @ApiOperation("根据主键查询分类表")
    @GetMapping("/{catId}")
    public AjaxResult findById(@PathVariable Serializable catId){
        return AjaxResult.success(categoryService.findById(catId));
    }

    @ApiOperation("新增分类表")
    @PostMapping
    public AjaxResult add(@RequestBody Category category){
        categoryService.add(category);
        return AjaxResult.success();
    }

    @ApiOperation("修改分类表")
    @PutMapping
    public AjaxResult modify(@RequestBody Category category){
        categoryService.modify(category);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除分类表")
    @DeleteMapping("/{catId}")
    public AjaxResult removeById(@PathVariable Serializable catId){
        categoryService.removeById(catId);
        return AjaxResult.success();
    }

}
